<template>
  <div class="myspelling">
    <backzj :mssg="aaa" />
    <!-- 顶部切换 -->
    <div class="opoad">
        <div class="dbudh">
            <div class="adfp" @click="qiehuan">
                <p :class="{ afag: index1 == 0, afag1: 1 }">已完成</p>
            </div>
            <div class="adfp" @click="qiehuan1">
                <p :class="{ afag: index1 == 1, afag1: 1 }">拼团中</p>
            </div>
        </div>
    </div>
     <!-- 顶部切换 -->
     <div class="nefng">
       <div v-for="(item,index) in arr" :key="index">
     <!-- 已完成样式 -->
        <div class="xpt" v-show="index1==0">
          <div class="uigas" @click="toptxq">
            <div class="xtop">
              <div class="xleft">
                  <div class="ximg">
                      <span class="xtuan">{{item.totalNum}}人团</span>
                  </div>
              </div>
              <div class="xjs">
                  <span>开始:{{item.endDate}}</span>
                </div>
              <div class="xdiqi">第{{item.periods}}期</div>
            </div>
            <div class="xbtop">
              <div class="xbleft">
                  <img :src="item.photos + '?' + randomNum" alt="">
              </div>
              <div class="xbright">
                <div class="xbjs">{{item.productName}}</div>
                <div class="bjdu">
                  <div class="jindt">
                      <mt-progress :value="item.cnt/item.totalNum*100" :bar-height="6"></mt-progress>
                  </div>
                  <div class="bbsy">
                        {{item.totalNum>item.cnt?'还差'+(item.totalNum-item.cnt)+'人':'已拼满'}}
                  </div>
                </div>
                <div class="xbptt">
                  <p class="xbjq">拼团价<span class="orange">￥{{item.oSpellprice}}</span></p>
                  <p class="xbjq">单品价<span class="xbsc">￥{{item.price}}</span></p>
                </div>
              </div>
            </div>
          </div>
            <div class="jksd" @click="toddxq">
                <p>{{item.orderId}}</p>
                <p v-if="item.pstatus==2 && item.checked==1 && item.win!=1">拼中红包<sp class="cored">￥{{item.couponMoney+item.secend_couponMoney}}</sp></p>
                <p v-if="item.pstatus==2 && item.checked==1 && item.win==1">拼中<sanp class="cored">商品</sanp></p>
                <p class="jdgl" v-if="item.write_off_type==1 && item.win==1 &&item.ostatus==1">待核销</p>
                <p class="jdgl" v-if="item.write_off_type==1 && item.win==1 &&item.ostatus==2">已核销</p>
                <p class="jdgl" v-if="item.write_off_type==1 && item.win==1 &&item.ostatus==-1">已失效</p>
                <p v-if="item.write_off_type==0 && item.win==1 && item.ostatus==1">待发货</p>
                <p v-if="item.write_off_type==0 && item.win==1 && item.ostatus==6">查看物流</p>
                <p v-if="item.write_off_type==0 && item.win==1 && item.ostatus==2">已完成</p>
                <p v-if="item.pstatus==2 && item.checked!=1">待查看</p>
                <p v-if="item.pstatus==0">拼团中</p>
                <p v-if="item.pstatus==3 && item.flag==2">解散，已续期</p>
                <p v-if="item.pstatus==3 && item.flag!=2">已解散</p>
                <p v-if="item.pstatus==1">已失效</p>
                <p class="pmh" v-if="item.pstatus!=3">订单详情></p>
            </div>
        </div>
     <!-- 已完成样式 -->
     <!-- 拼团中 -->
        <div class="xpt" v-show="index1==1">
            <div class="xtop">
                <div class="xleft">
                    <div class="ximg">
                        <span class="xtuan">{{item.totalNum}}人团</span>
                    </div>
                </div>
                <!-- <div class="xjs"><span class="cored">3</span>人拼中商品,<span class="cored">3</span>人各得<span class="cored">￥99.9</span></div> -->
                <div class="xjs">
                  <span>截止:{{item.endDate}}</span>
                </div>
                <div class="xdiqi">第{{item.periods}}期</div>
            </div>
            <div class="xbtop" @click="topt">
                <div class="xbleft">
                    <img :src="item.photos + '?' + randomNum" alt="">
                </div>
                <div class="xbright">
                    <div class="xbjs">{{item.productName}}</div>
                    <div class="bjdu">
                        <div class="jindt">
                            <mt-progress :value="item.cnt/item.totalNum*100" :bar-height="6"></mt-progress>
                        </div>
                        <div class="bbsy">
                        {{item.totalNum>item.cnt?'还差'+(item.totalNum-item.cnt)+'人':'已拼满'}}
                  </div>
                    </div>
                    <div class="xbptt">
                        <p class="xbjq">拼团价<span class="orange">￥{{item.oSpellprice}}</span></p>
                        <p class="xbjq">单品价<span class="xbsc">￥{{item.price}}</span></p>
                    </div>
                </div>
            </div>
            <div class="jksd">
                <p>{{item.orderId}}</p>
                <p>拼团中</p>
                <p class="kdsig">查看拼团详情</p>
            </div>
        </div>
     <!-- 拼团中 -->
     </div>
    </div>
  </div>
</template>

<script>
import backzj from "../components/backzj.vue";
import Utils from "../utils/util.js";
import { getsj } from "../api/jjj";
export default {
  components: { backzj },
  data() {
    return {
      aaa: "我的拼团",
      DataURL: "https://e.amjhome.com/baojiayou/tts_upload",
      SMDataURL: "https://bjy.51yunkeyi.com/baojiayou/tts_upload",
      randomNum: Math.random() / 9999,
      iimg: "",
      index1: 0,
      arr: "",
      arr1: [1, 1, 1, 1],
    };
  },
  methods: {
    qiehuan() {
      this.index1 = 0;
      let userId = this.$store.getters.sidebar.userId;
    let timestamp = Date.parse(new Date()) / 1000;
    let qm =
      "cls=product_goodtype&action=QuerySpellOrder" +
      "&appId=1" +
      "&timestamp=" +
      timestamp;
    let dfg =
      "&mbfg=0,1" + "&userId=" + userId + "&status=2&valid=0&pSize=20&pIndex=1";
    getsj("aa", "b", qm, dfg)
      .then((res) => {
        let arr1 = res.data.data;
        for (var i = 0; i < arr1.length; i++) {
          let iitem = arr1[i];
          iitem.photos = iitem.photos.split(",");
          iitem.photos = iitem.photos[0];
          console.log(iitem.photos);
        }
        this.arr = res.data.data;
      })
      .catch((err) => {
        console.log(err);
      });
    },
    qiehuan1() {
      this.index1 = 1;
      let userId = this.$store.getters.sidebar.userId;
      let timestamp = Date.parse(new Date()) / 1000;
      let qm =
        "cls=product_goodtype&action=QuerySpellOrder" +
        "&appId=1" +
        "&timestamp=" +
        timestamp;
      let dfg =
        "&mbfg=0,1" +
        "&userId=" +
        userId +
        "&status=0&valid=1&pSize=20&pIndex=1";
      getsj("aa", "b", qm, dfg)
        .then((res) => {
          let arr1 = res.data.data;
          for (var i = 0; i < arr1.length; i++) {
            let iitem = arr1[i];
            iitem.photos = iitem.photos.split(",");
            iitem.photos = iitem.photos[0];
            console.log(iitem.photos);
          }
          this.arr = res.data.data;
        })
        .catch((err) => {
          console.log(err);
        });
    },
    toptxq() {
      this.$router.push({
        path: "/pintuan",
        query: {
          xianshi: "",
        },
      });
    },
    topt() {
      this.$router.push({
        path: "/pintuan",
        query: {
          xianshi: "1",
        },
      });
    },
    toddxq() {
      this.$router.push("/successDetailspa");
    },
  },
  created() {
    let userId = this.$store.getters.sidebar.userId;
    let timestamp = Date.parse(new Date()) / 1000;
    let qm =
      "cls=product_goodtype&action=QuerySpellOrder" +
      "&appId=1" +
      "&timestamp=" +
      timestamp;
    let dfg =
      "&mbfg=0,1" + "&userId=" + userId + "&status=2&valid=0&pSize=20&pIndex=1";
    getsj("aa", "b", qm, dfg)
      .then((res) => {
        let arr1 = res.data.data;
        for (var i = 0; i < arr1.length; i++) {
          let iitem = arr1[i];
          iitem.photos = iitem.photos.split(",");
          iitem.photos = iitem.photos[0];
          console.log(iitem.photos);
        }
        this.arr = res.data.data;
      })
      .catch((err) => {
        console.log(err);
      });
  },
};
</script>

<style scoped>
.myspelling {
  width: 94%;
  margin: 0 auto;
}
.opoad {
  width: 100%;
  height: 82px;
  position: fixed;
  left: 0;
  top: 0;
}
.dbudh {
  width: 100%;
  height: 38px;
  display: flex;
  align-items: center;
  margin-top: 44px;
}
.nefng {
  position: fixed;
  left: 3%;
  top: 88px;
  width: 94%;
  height: calc(100% - 88px);
  overflow-y: auto;
}
.adfp {
  width: 50%;
  height: 100%;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.afag1 {
  padding-bottom: 2px;
  border-bottom: 2px rgba(255, 255, 255, 0) solid;
}
.afag {
  padding-bottom: 2px;
  color: #428ceb;
  border-bottom: 2px #428ceb solid;
}
/* 顶部切换 */
/* 已完成样式 */
.xpt {
  display: flex;
  flex-direction: column;
  margin: 4px 0 16px 0;
}
.xtop {
  width: 100%;
  display: flex;
  align-items: center;
  background: #eee;
  justify-content: space-between;
  margin: 0 auto;
  border-radius: 4px;
  box-sizing: border-box;
  font-size: 14px;
}
.xleft {
  display: flex;
  align-items: center;
  /* margin-left: 10rpx; */
}
.ximg {
  width: 88px;
  height: 30px;
  line-height: 30px;
  text-align: center;
  background: #f8df95;
  border-radius: 6px 50px 50px 6px;
}
.ximg img {
  max-width: 100%;
  max-height: 100%;
}
.xtuan {
  margin-right: 12px;
}
.xjs {
  margin-left: 5px;
}
.cored {
  color: #ff3333;
}
.xbtop {
  display: flex;
  align-items: center;
  margin-top: 6px;
}
.xbleft {
  width: 110px;
  height: 110px;
  border: 1px solid gainsboro;
  border-radius: 4px;
  margin-right: 10px;
}
.xbleft img {
  max-width: 100%;
  max-height: 100%;
}
.xbright {
  width: 65%;
  /* border: 1rpx solid red; */
  display: flex;
  flex-direction: column;
}
.xbjs {
  font-weight: 700;
  color: #333333;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.xbptt {
  display: flex;
  align-items: center;
  margin: 3px 0;
}
.xbjq {
  font-size: 15px;
  font-weight: 400;
  margin-right: 15px;
}
.orange {
  color: #f07244;
}
.xbsc {
  font-size: 15px;
  font-weight: 400;
  text-decoration: line-through;
  color: #999999;
}
.bjdu {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.jindt {
  width: 72%;
}
.jdtsz {
  color: #666;
  font-size: 14px;
}
.xrhd {
  font-size: 12px;
  font-weight: 700;
}
.jindt /deep/ .mt-progress-runway {
  border-radius: 4px;
}
.jindt /deep/ .mt-progress-progress {
  background: #f4793b;
  border-radius: 4px;
}
.jksd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 2px;
  font-size: 14px;
  color: #333;
}
.kdsig {
  padding: 1px 10px;
  background: #f07244;
  color: white;
  border-radius: 4px;
}
.bbsy {
  font-size: 14px;
  color: #333;
}
/* 已完成样式 */
</style>